﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Flash
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple=true)]
    public class AccessRuleAttribute : Attribute
    {
        public AccessRuleAttribute(AccessRuleType ruleType, string value)
        {
            value = value.Trim();

            if ((value == "*" || value == "?") && (ruleType == AccessRuleType.AllowRole || ruleType == AccessRuleType.DenyRole))
            {
                throw new ArgumentException("The role cannot be '?' or '*'.");
            }

            this.RuleType = ruleType;
            this.Value = value;
        }

        public AccessRuleType RuleType { get; private set; }
        public string Value { get; private set; }
    }

    public enum AccessRuleType : byte
    {
        AllowUser,
        DenyUser,
        AllowRole,
        DenyRole
    }
}
